const mongoose = require('mongoose');
mongoose.connect('mongodb://127.0.0.1:27017/my-nodejs-project');

const db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function() {
  console.log('we\'re connected!');
});

// 构建 users 的 model
const usersSchema = mongoose.Schema({
  username: {
    type: String,
    required: true
  },
  age: {
    type: Number,
    required: true
  },
  sex: {
    type: Number,
    required: true
  },
  password: {
    type: String,
  },
  createTime: {
    type: Number
  },
  modifyTime: {
    type: Number,
  },
  userPhoto: {
    path: {
      type: String,
      select: true
    },
    filename: {
      type: String,
      select: true
    },
  },
});

const Users = mongoose.model('users', usersSchema);

// 构建 Files 的 model
const filesSchema = mongoose.Schema({
  filename: {
    type: String,
    required: true
  },
  createTime: {
    type: Number
  },
});

const Files = mongoose.model('files', filesSchema);

exports.Users = Users
exports.Files = Files


